#include <bits/stdc++.h>
using namespace std;
int n, c[10010], f[101][101], b[10010], top;
bool dfs(int x, int y)
{
	if(x == y)
		return 1;
	else
	{
		for(int i = 1; i <= n; i++)
		{
			if(f[x][i] == 1)
				return dfs(i, y);
		}
	}
}
bool check(int x)
{
	c[x] = 1;
	for(int i = 1; i <= n; i++)
	{
		if(c[i] == 0)
		{
			for(int j = 1; j <= n; j++){
				f[i][j] = 0;
				f[j][i] = 0;
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(c[i] && !dfs(x, i))
			return 0;
	}
	return 1;
}
void jk(int k)
{
	for(int i = 1; i <= n; i++)
	{
		if(c[i] == 0)
		{
			if(check(c[i]) == 1)
			{
				b[++top] = k;
				return ;
			}
			else
			{
				c[i] = 1;
				jk(k+1);
				c[i] = 0;
			}
		}
	}
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> c[i];
	for(int i = 1; i <= n - 1; i++)
	{
		int x, y;
		cin >> x >> y;
		f[x][y] = 1;
		f[y][x] = 1;
	}
	jk(0);
	cout << *min_element(b + 1, b + 1 + top) << endl;
	return 0;
}